<template>
    <van-nav-bar title="订单页" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-contact-card type="add" @click="onAdd" v-show="flag" />
    <van-address-list v-model="userid" :list="list" default-tag-text="默认" />
    <van-empty image="error" description="暂无订单" />

    <van-submit-bar button-text="合计">
        <template #tip>
        </template>
    </van-submit-bar>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import { ref } from "vue"
import { mrAddress } from '@/service/order';
import { useCounterStore } from "@/stores/counter"
let store = useCounterStore()
let router = useRouter()
let flag = ref(true)
let list = ref([] as any)
let userid = ref((store as any).userInfo.userid)
const onClickLeft = () => {
    router.push("/user")
}
const onAdd = () => {
    router.push("/address")
}
const addOrder = () => {
    mrAddress(userid.value).then((res: any) => {
        if (res.code === "200") {
            list.value = res.data.map((item: any) => ({
                id: item.addressid,
                tel: item.tel,
                name: item.name,
                isDefault: item.isDefault
            }))
        }
        if(list.value.length!==0){
            flag.value = false
        }
    })
}
addOrder()
</script>

<style scoped>

</style>